#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 2;
const int mod = 998244353;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    int a[maxn];
    int b[maxn];
    cin >> n >> m;

    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }

    for (int i = 1; i <= m; i++)
    {
        cin >> b[i];
    }

    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

    // Initialize dp[1][i] and dp[i][1]
    for (int i = 2; i <= n; i++)
    {
        dp[i][1] = dp[i - 1][1] + abs(a[i] + b[1] - (a[i - 1] + b[1]));
    }

    for (int i = 2; i <= m; i++)
    {
        dp[1][i] = dp[1][i - 1] + abs(a[1] + b[i] - (a[1] + b[i - 1]));
    }

    // Fill dp table
    for (int i = 2; i <= n; i++)
    {
        for (int j = 2; j <= m; j++)
        {
            dp[i][j] = max(dp[i - 1][j] + abs(a[i] + b[j] - (a[i - 1] + b[j])),
                           dp[i][j - 1] + abs(a[i] + b[j] - (a[i] + b[j - 1])));
        }
    }

    cout << dp[n][m] << endl;
    return 0;
}
